/*
 * Copyright 2008 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.splink.library.logging {
	import flash.system.Capabilities;
	import flash.utils.getTimer;

	/**
	 * If you log a message via an <code>ILogger</code> instance the <code>ILogger</code> default
	 * implementation <code>Logger</code> creates a <code>LogEvent</code> storing information
	 * related to the log message. Depending if the flash movie is played via flash debug player
	 * or not, the log event contains information about the location where the log message originates 
	 * from. (functionname, line number)
	 * 
	 * @author Max Kugland
	 */
	public class LogEvent {
		private var _timestamp : uint;
		private var _level : uint;
		private var _message : String;
		private var _className : String;
		private var _fncName : String;
		private var _lineNr : uint;

		public function LogEvent(stacktrace : StackTrace, level : uint, message : String) {
			_timestamp = getTimer();
			_className = stacktrace.clazz;
			_fncName = stacktrace.method;
			_lineNr = stacktrace.line;
			_level = level;
			_message = message;
		}

		/**
		 * @return the timestamp when a the <code>LogEvent</code> occured
		 */
		public function getTimestamp() : uint {
			return _timestamp;
		}

		/**
		 * @return the <code>LogEvent</code> level
		 * @see LogLevel
		 */
		public function getLevel() : uint {
			return _level;
		}

		/**
		 * @return the log message
		 */
		public function getMessage() : String {
			return _message;
		}

		/**
		 * Returns the name of the function in which the log event originated. If the flash player
		 * in which the movie is played is not a debug player returns null. 
		 * 
		 * @return the name of the function in which the log event originated
		 */
		public function getFncName() : String {
			if(getIsDebugPlayer()) return _fncName;
			return null;
		}

		/**
		 * Returns the line number of the function in which the log event originated. If the flash 
		 * player in which the movie is played is not a debug player returns null.
		 *  
		 * @return the line number in which the log event originated
		 */
		public function getLineNr() : uint {
			if(getIsDebugPlayer()) return _lineNr;
			return null;
		}

		/**
		 * @return the name of the class in which the log event originated
		 */
		public function getClassName() : String {
			return _className;
		}

		/**
		 * @return true if the flash movie is played via flash debug player. This enables the default
		 * <code>ILogger</code> imlementation <code>Logger</code> to resolve where the log originated. 
		 */
		public function getIsDebugPlayer() : Boolean {
			return Capabilities.isDebugger;	
		}
	}
}
